package com.hmall.item.config;

import org.springframework.stereotype.Component;

    @Component
public class ThreadLocalConfig {

        // jdk建议将 ThreadLocal 定义为 private static ，这样就不会有弱引用，内存泄漏的问题了
        private static ThreadLocal<String> mapThreadLocal = new ThreadLocal<>();

        //获取当前线程的存的变量
        public String get() {
            return mapThreadLocal.get();
        }

        //设置当前线程的存的变量
        public void set(String userId) {
            this.mapThreadLocal.set(userId);
        }

        //移除当前线程的存的变量
        public void remove() {
            this.mapThreadLocal.remove();
        }
}
